/*
===========================================================================
Copyright (C) 2013-2014 Avotu Briezhaudzetava

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

===========================================================================
*/

#ifndef PRECURSORENTRY_H
#define PRECURSORENTRY_H

//
// includes
//
#include "databaseentry.h"
#include "common.h"

//
// class: PrecursorEntry
//
class PrecursorEntry : public DatabaseEntry {
    Q_PROPERTY( QString title READ title WRITE setTitle )
    Q_PROPERTY( float density READ density WRITE setDensity )
    Q_PROPERTY( float baseAmount READ baseAmount WRITE setBaseAmount )
    Q_PROPERTY( QString lot READ lot WRITE setLot )
    Q_PROPERTY( Main::Units units READ units WRITE setUnits )
    Q_PROPERTY( bool solvent READ isSolvent WRITE setSolvent )

public:
    explicit PrecursorEntry( const QSqlRecord &record, const QString &table );
    ~PrecursorEntry();

    QString title() const { return this->record().value( "title" ).toString(); }
    float density() const { return this->record().value( "density" ).toFloat(); }
    float baseAmount() const { return this->record().value( "baseAmount" ).toFloat(); }
    QString lot() const { return this->record().value( "lot" ).toString(); }
    Common::Units units() const { return static_cast<Common::Units>( this->record().value( "units" ).toInt()); }
    bool isSolvent() const { return static_cast<bool>( this->record().value( "solvent" ).toInt()); }
    float baseAmountTo( Common::Units baseUnits ) const;

public slots:
    void setTitle( const QString &title ) { this->setValue( "title", title ); }
    void setDensity( float density ) { this->setValue( "density", density ); }
    void setBaseAmount( float baseAmount ) { this->setValue( "baseAmount", baseAmount ); }
    void setLot( const QString &lot ) { this->setValue( "lot", lot ); }
    void setUnits( Common::Units units ) { this->setValue( "units", static_cast<int>( units )); }
    void setSolvent( bool solvent = true ) { this->setValue( "solvent", static_cast<int>( solvent )); }
};

#endif // PRECURSORENTRY_H
